package com.mm.ai.controller;

import com.mm.ai.service.OssService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

/**
 * @Author：tangnaichao
 * @Date：2024/10/25 20:48
 */
@Controller
@RequestMapping("/oss/")
public class OSSController {
    @Autowired
    private OssService ossService;

    @ResponseBody
    @PostMapping("/uploadFile")
    public String saveFile(@RequestParam("file") MultipartFile multipartFile) {
        ossService.uploadFile(multipartFile);
        return "uploadFile successfully.";
    }

    @ResponseBody
    @PostMapping("/saveFile")
    public String saveFile(@RequestParam("osskey") String fileName, @RequestBody String content) {
        ossService.saveFile(fileName, content);
        return "File saved successfully.";
    }

    @ResponseBody
    @GetMapping("/downloadFile")
    public String downloadFile(@RequestParam("osskey") String osskey) {
        return ossService.downloadFile(osskey);
    }

    @GetMapping("/")
    public String showEditor(Model model) {
        return "editOSSFile";
    }
}
